﻿using System;
using System.Windows.Forms;

using Microsoft.VisualBasic.ApplicationServices;

namespace QuickTuner.Util
{
    /// <summary>
    /// Provides instance-controlling services.
    /// </summary>
    /// <remarks>
    /// Creation of main form is deferred it is unsure that an instance is not already running.
    /// </remarks>
    public class InstanceController : WindowsFormsApplicationBase
    {
        private readonly Func<Form> _createMainFormFunc;

        public InstanceController(Func<Form> createMainFormFunction, bool isSingleInstance)
        {
            this.IsSingleInstance = isSingleInstance;
            _createMainFormFunc = createMainFormFunction;
        }

        protected override void OnCreateMainForm()
        {
            this.MainForm = _createMainFormFunc();

            base.OnCreateMainForm();
        }
    }
}